package com.ruoyi.project.system.personnel.controller;

import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.personnel.domain.Apply;
import com.ruoyi.project.system.personnel.service.IApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 申请  控制层
 * @author LHF
 */
@Controller
@RequestMapping("/system/apply")
public class ApplyController extends BaseController {

    private String prefix = "system/apply";

    @Autowired
    private IApplyService applyService;

    private ServerConfig serverConfig = new ServerConfig();

    @GetMapping()
    public String info() {
        return prefix + "/apply";
    }


    /**
     * 根据调价查询所有申请
     *
     * @param title     标题
     * @param applicant 申请人
     * @return
     */
    @PostMapping("list")
    @ResponseBody
    public TableDataInfo applyList(String title, String applicant) {
        startPage();
        List<Apply> applies = applyService.queryAllApply(title, applicant);
        return getDataTable(applies);
    }

    /**
     * 新增申请
     *
     * @return
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }


    /**
     * 添加申请  数据提交
     *
     * @param apply
     * @return
     */
    @PostMapping("/add/submit")
    @ResponseBody
    public AjaxResult submit(Apply apply) {
        return toAjax(applyService.addSubmit(apply));
    }

    /**
     * 删除申请信息
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(applyService.deleteInfo(ids));
    }


    /**
     * 修改申请
     *
     * @param applyId
     * @param mmap
     * @return
     */
    @GetMapping("/edit/{applyId}")
    public String edit(@PathVariable("applyId") Long applyId, ModelMap mmap) {

        mmap.put("apply", applyService.selectApplyById(applyId));
        return prefix + "/edit";
    }

    /**
     * 修改保存申请
     *
     * @param apply
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Apply apply) {
        return toAjax(applyService.updateApply(apply));
    }


}
